/*
 * Copyright 2002-2006 the original author or authors. Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific language governing permissions and limitations under the
 * License.
 */
package pikes.html.xhtml;

import pikes.core.Printable;
import pikes.core.PrintableCharSequence;
import pikes.uri.RelativeURI;
import pikes.uri.URI;
import pikes.util.Assert;
import pikes.xml.XMLTag;

/**
 * <code>&lt;script/&gt;</code> tag, see <a href="http://www.w3.org/TR/html401/interact/scripts.html#h-18.2.1">SCRIPT
 * element</a> in HTML specification.
 * @author Peter Bona
 * @see <a href="http://www.w3.org/TR/html401/interact/scripts.html#h-18.2.1">The SCRIPT element in HTML specification</a>
 */
public class Script extends HeadMisc implements Special {

	private CharSequence type = null;

	private URI src = null;

	private Printable code = null;

	public Script(CharSequence type) {
		Assert.hasText(type);
		this.type = type;
	}

	public Script(CharSequence type, CharSequence src) {
		this(type, new RelativeURI(src));
	}

	public Script(CharSequence type, URI src) {
		this(type);
		this.src = src;
	}

	/**
	 * @return "script"
	 */
	@Override
	protected CharSequence getTagName() {
		return "script";
	}

	@Override
	protected void decorateCreatedTag(XMLTag tag) {
		if (type != null) {
			tag.addAttribute("type", type);
		}

		if (src != null) {
			tag.addAttribute("src", src);
		}

		if (code != null) {
			tag.addText(code);
		}
	}

	public void setCode(CharSequence code) {
		this.code = new PrintableCharSequence(code);
	}

	public Printable getCode() {
		return code;
	}

	public void setCode(Printable code) {
		this.code = code;
	}

}
